package com.hns.phone.master.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Service;

import com.hns.can.base.entity.SysRoleEntity;
import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.aop.sedate.SedateAnnotation;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.phone.master.vo.PhoneDataReportInfoVo;
import com.hns.phone.master.vo.PhoneDataReportParamsVo;
import com.hns.phone.master.vo.PhoneLineBhvDataVo;
import com.hns.tool.pub.PubUtil;

/**
 * 数据报告service
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class PhoneDataReportService extends CommonService {

	/**
	 * 获取数据报告
	 * @param date
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public PhoneDataReportInfoVo getDataReportInfo(String date, ArrayList<SysRoleEntity> roleList,SysUserEntity user) {
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		PhoneDataReportInfoVo phoneDataReportInfoVo = null;
		HashMap hashMap = new HashMap();
		hashMap.put("date", date);
		hashMap.put("roleIdList", roleList);
		hashMap.put("userId", user.getId());
		List<PhoneDataReportInfoVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("dataReport.getdataReportInfo", hashMap), PhoneDataReportInfoVo.class);
		if(PubUtil.isNotEmpty(list)){
			phoneDataReportInfoVo = list.get(0);
		}
		return phoneDataReportInfoVo;
	}


	/**
	 * 获取历史数据报告
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getDataHistoryReport(ArrayList<SysRoleEntity> roleList,SysUserEntity user) {
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		HashMap hashMap = new HashMap();
		hashMap.put("roleIdList", roleList);
		hashMap.put("userId", user.getId());
		Pagination page = this.myBatisPage("dataReport.getdataReportCnt", "dataReport.getdataReportInfo", hashMap, PhoneDataReportInfoVo.class);
		return page;
	}

	
	/**
	 * 获取线路数据报告
	 * @param date
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getLineDataReport(String date, ArrayList<SysRoleEntity> roleList) {
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		HashMap hashMap = new HashMap();
		hashMap.put("date", date);
		hashMap.put("roleIdList", roleList);
		Pagination page = this.myBatisPage("dataReport.getLineDataReportCnt", "dataReport.getLineDataReportData", hashMap, PhoneDataReportInfoVo.class);
		return page;
	}

	/**
	 * 线路故障数据
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("unchecked")
	@SedateAnnotation
	public PhoneDataReportInfoVo getLineFaultData(CommonParamsVo params, ArrayList<SysRoleEntity> roleList) {
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		params.setRoleList(roleList);
		PhoneDataReportInfoVo phoneDataReportInfoVo = null;
		List<PhoneDataReportInfoVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("dataReport.getLineFaultData", params), PhoneDataReportInfoVo.class);
		if(PubUtil.isNotEmpty(list)){
			phoneDataReportInfoVo = list.get(0);
		}
		return phoneDataReportInfoVo;
	}
	
	/**
	 * 线路行为数据
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "unused", "unchecked" })
	@SedateAnnotation
	public List<PhoneLineBhvDataVo> getLineBhvData(CommonParamsVo params, ArrayList<SysRoleEntity> roleList){
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String today = dateFormat.format(new Date());
		if(today.equals(params.getDate())){
			params.setBeginTime(null);
			params.setEndTime(null);
		}
		
		params.setRoleList(roleList);
		PhoneLineBhvDataVo phoneLineBhvDataVo = null;
		List<PhoneLineBhvDataVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("dataReport.getLineBhvData", params), PhoneLineBhvDataVo.class);
		return list;
	}

	/**
	 * 线路能耗汇总
	 * @param params
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("unchecked")
	public PhoneLineBhvDataVo getLineEnergyData(PhoneDataReportParamsVo params, ArrayList<SysRoleEntity> roleList) {
//		ArrayList<SysRoleEntity> roleList = new ArrayList<SysRoleEntity>(this.getAppCurrentUser().getSet_role());
		params.setRoleList(roleList);
		PhoneLineBhvDataVo phoneLineBhvDataVo = null;
		List<PhoneLineBhvDataVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("dataReport.getLineEnergyData", params), PhoneLineBhvDataVo.class);
		if(PubUtil.isNotEmpty(list)){
			phoneLineBhvDataVo = list.get(0);
		}
		return phoneLineBhvDataVo;
	}
	
	
	
}
